#include "header.h"

class Rational
{
        int x;
        int y; 
public:
        Rational(int=0, int=1);
        Rational(const Rational&);
        ~Rational(); 
        void afisare();
        int getNum();
		void setNum(int);
		int getNr();
		void setNr(int);
};

Rational::Rational(int x, int y)
{
        this->x = x;
        this->y = y;
}

Rational::~Rational()
{
}

Rational::Rational(const Rational& z)
{
        this->x = z.x;
        this->y = z.y;
}

void Rational::afisare()
{
        cout << x << "/" << y << " ";
}

int Rational::getNr()
{
	return this->x;
}

int Rational::getNum()
{
	return this->y;
}

void Rational::setNr(int x)
{
	this->x=x;
}

void Rational::setNum(int y)
{
	this->y=y;
}

int diviz(int nr1,int nr2)
{
        while(nr1!=nr2)
        {
                if(nr1>nr2)
                        nr1-=nr2;
                else
                        nr2-=nr1;
        }
        return nr1;
}

void Adunare(Rational nr1,Rational nr2)
{
	Rational tmp;
	tmp.setNr(nr1.getNr()*nr2.getNum()+nr2.getNr()*nr1.getNum());
	tmp.setNum(nr1.getNum()*nr2.getNum());
	nr1.afisare();
	cout<<" + ";
	nr2.afisare();
	cout<<" = ";
	tmp.afisare();
	cout<<endl;
}

void Scadere(Rational nr1,Rational nr2)
{
	Rational tmp;
	tmp.setNr(nr1.getNr()*nr2.getNum()-nr2.getNr()*nr1.getNum());
	tmp.setNum(nr1.getNum()*nr2.getNum());
	nr1.afisare();
	cout<<" - ";
	nr2.afisare();
	cout<<" = ";
	tmp.afisare();
	cout<<endl;
}

void Inmultire(Rational nr1,Rational nr2)
{
	Rational tmp;
	tmp.setNr(nr1.getNr()*nr2.getNr());
	tmp.setNum(nr1.getNum()*nr2.getNum());
	nr1.afisare();
	cout<<" * ";
	nr2.afisare();
	cout<<" = ";
	tmp.afisare();
	cout<<endl;
}

void Impartire(Rational nr1,Rational nr2)
{
	Rational tmp;
	tmp.setNr(nr1.getNr()*nr2.getNum());
	tmp.setNum(nr1.getNum()*nr2.getNr());
	if(tmp.getNum()==0)
	{
		cout<<"Impartire la 0";
	}
	else
	{
		nr1.afisare();
		cout<<" / ";
		nr2.afisare();
		cout<<" = ";
		tmp.afisare();
	}
	cout<<endl;
}

int main()
{
        Rational r1(1,2);
		Rational r2;
		Rational r3(5);
		Rational r4(r1);
		Adunare(r1,r2);
		Scadere(r3,r2);
		Inmultire(r1,r4);
		Impartire(r2,r3);
        _getch();
        return 0;
}